<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="职位ID" prop="qdkbId">
        <el-input
          type="number"
          v-model="queryParams.qdkbId"
          placeholder="请输入职位ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职位名" prop="positionName">
        <el-input
          v-model="queryParams.positionName"
          placeholder="请输入职位名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="寻访顾问" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入寻访顾问"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工编号" prop="ygNo">
        <el-input
          v-model="queryParams.ygNo"
          placeholder="请输入员工编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入员工姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="tel">
        <el-input
          v-model="queryParams.tel"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提现状态" prop="statusOne">
        <el-select
          clearable
          v-model="queryParams.withdrawalStatus"
          @keyup.enter.native="handleQuery"
        >
          <el-option label="待提现" value="1"> </el-option>
          <el-option label="提现中" value="2"> </el-option>
          <el-option label="提现完成" value="3"> </el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <div
      style="
        display: flex;
        justify-content: space-between;
        align-items: anchor-center;
      "
    >
      <el-radio-group
        v-model="queryParams.backStatus"
        style="margin-bottom: 10px"
        size="mini"
        @change="listTab()"
      >
        <el-radio-button label="2">收入明细</el-radio-button>
        <el-radio-button label="1">待确认</el-radio-button>
        <el-radio-button label="3">未通过</el-radio-button>
      </el-radio-group>
      <el-button
        type="warning"
        plain
        icon="el-icon-download"
        size="mini"
        @click="handleExport"
        v-hasPermi="['system:slmx:export']"
        >导出</el-button
      >
    </div>
    <el-table
      v-loading="loading"
      :data="slmxList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="员工编号" align="center" prop="ygNo" />
      <el-table-column label="姓名" align="center" prop="name" />

      <el-table-column label="手机号" align="center" prop="tel" />
      <el-table-column label="项目名称" align="center">
        <template slot-scope="scope">
          {{ "【" + scope.row.brandName + "】-" + scope.row.positionName }}
        </template>
      </el-table-column>
      <el-table-column label="返费金额" align="center" prop="money" />
      <el-table-column label="累计返费" align="center">
        <template slot-scope="scope">
          {{ queryParams.backStatus == 2 ? scope.row.backMoney : "-" }}
        </template>
      </el-table-column>
      <el-table-column label="寻访顾问" align="center" prop="userName" />
      <el-table-column label="入职日期" align="center" prop="entryTime">
      </el-table-column>
      <el-table-column label="离职日期" align="center" prop="resignationTime">
        <template slot-scope="scope">
          {{ scope.row.resignationTime || "-" }}
        </template>
      </el-table-column>
      <el-table-column
        label="PM"
        align="center"
        prop="positionResponsiblePerson"
      />
      <el-table-column label="返费状态" align="center" width="120">
        <template slot-scope="scope">
          <el-tag>{{ srmxStatus.backStatusList[scope.row.backStatus] }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="提现状态" align="center" width="120">
        <template slot-scope="scope" v-if="queryParams.backStatus == 2">
          <el-tag>{{
            srmxStatus.withdrawalStatusList[scope.row.withdrawalStatus]
          }}</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="寻访职位" align="center" width="120">
        <template slot-scope="scope">
          <el-link
            type="primary"
            @click="seeqdkb(scope.row.qdkbId)"
            :underline="false"
            >{{ scope.row.positionName }}</el-link
          >
        </template>
      </el-table-column>

      <el-table-column label="原因" align="center">
        <template slot-scope="scope">
          {{ queryParams.backStatus == 3 ? scope.row.reason : "-" }}
        </template>
      </el-table-column>

      <el-table-column label="更新时间" align="center" prop="" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.updateTime }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        fixed="right"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row, true)"
            v-if="scope.row.backStatus == 1"
            v-hasPermi="['system:slmx:edit']"
          >
            审核
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row, false)"
            v-if="scope.row.backStatus == 3"
            v-hasPermi="['system:slmx:edit']"
          >
            重新审核
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="状态" prop="backStatus">
          <el-radio-group v-model="form.backStatus">
            <el-radio label="2">通过</el-radio>
            <el-radio label="3" v-if="restate">未通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="返费金额" prop="money" v-if="form.backStatus == 2">
          <el-input-number
            v-model="form.money"
            :precision="2"
          ></el-input-number>
        </el-form-item>
        <el-form-item label="原因" prop="reason" v-if="form.backStatus == 3">
          <el-input
            v-model="form.reason"
            type="textarea"
            placeholder="请输入内容"
            maxlength="300"
            show-word-limit
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-drawer
      title="职位信息"
      :visible.sync="open1"
      direction="ltr"
      width="40%"
    >
      <el-form label-position="left" class="demo-table-expand">
        <el-form-item label=""><h3>职位基本信息</h3></el-form-item>
        <div style="border-bottom: 1px solid #e6ebf5">
          <el-row :gutter="10" class="mb8">
            <el-col :span="12"
              ><el-form-item label="职位名称:">
                {{ qdkbData.positionName }}
              </el-form-item></el-col
            >
            <el-col :span="12"
              ><el-form-item label="用工类型:">
                {{ qdkbData.employmentType }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="品牌:">
                {{ qdkbData.brandName }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="需求入职:">
                {{ qdkbData.requiredQuantity }}人
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="职能:">
                {{ qdkbData.fn }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="工作地点:">
                {{ qdkbData.workAdress }}
              </el-form-item></el-col
            >
          </el-row>
        </div>
        <div style="border-bottom: 1px solid #e6ebf5">
          <el-row :gutter="10" class="mb8">
            <el-col :span="12"
              ><el-form-item label="年龄:">
                {{ qdkbData.ageRange || "不限" }}
              </el-form-item></el-col
            >
            <el-col :span="12"
              ><el-form-item label="性别:">
                {{ qdkbData.genderRequirement || "不限" }}
              </el-form-item></el-col
            >
            <el-col :span="12"
              ><el-form-item label="学历:">
                {{ qdkbData.educationRequirement || "不限" }}
              </el-form-item></el-col
            >
            <el-col :span="12"
              ><el-form-item label="工作经验:">
                {{ qdkbData.experienceRequirement || "不限" }}
              </el-form-item></el-col
            >
          </el-row>
        </div>
        <div>
          <el-row :gutter="10" class="mb8">
            <el-col :span="24"
              ><el-form-item label="面试地点:">
                {{ qdkbData.interviewAddress }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="面试时间:">
                {{ qdkbData.interviewStartDate }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="结束时间:">
                {{ qdkbData.interviewSendDate }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="工作时间:">
                {{ qdkbData.workDate }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="职位负责人:">
                {{ qdkbData.positionResponsiblePerson }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="职位负责人电话:">
                {{ qdkbData.phonenumber }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="职位参与人:">
                {{ qdkbData.positionParticipants }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="职位亮点:">
                {{ qdkbData.positionHighlights }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="职位描述:">
                {{ qdkbData.positionDescription }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="沟通要点:">
                {{ qdkbData.communicate }}
              </el-form-item></el-col
            >
          </el-row>
        </div>
        <el-form-item label=""><h3>薪资福利</h3></el-form-item>
        <div>
          <el-row :gutter="10" class="mb8">
            <el-col :span="24"
              ><el-form-item label="基本薪资:">
                {{ qdkbData.baseSalary }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="综合薪资:">
                {{ qdkbData.totalSalary }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="其他构成:">
                {{ qdkbData.salaryComponents }}
              </el-form-item></el-col
            >
            <el-col :span="24"
              ><el-form-item label="薪资备注:">
                {{ qdkbData.salaryNotes }}
              </el-form-item></el-col
            >
            <el-col :span="6"
              ><el-form-item label="提供住宿:">
                {{ qdkbData.hasHousingProvided == "Y" ? "是" : "否" }}
              </el-form-item></el-col
            >
            <el-col :span="6"
              ><el-form-item label="社保:">
                {{ qdkbData.hasSocialInsurance == "Y" ? "是" : "否" }}
              </el-form-item></el-col
            >
            <el-col :span="6"
              ><el-form-item label="商保:">
                {{ qdkbData.hasCommercialInsurance == "Y" ? "是" : "否" }}
              </el-form-item></el-col
            >
            <el-col :span="6"
              ><el-form-item label="公积金:">
                {{ qdkbData.hasHousingFund == "Y" ? "是" : "否" }}
              </el-form-item></el-col
            >
          </el-row>
        </div>
      </el-form>
    </el-drawer>
  </div>
</template>

<script>
import {
  listSlmx,
  delSlmx,
  repeatUpdateSlmx,
  updateSlmx,
} from "@/api/system/slmx";
import { srmxStatus } from "@/utils/data.js";
import { getQdkb } from "@/api/system/qdkb";
export default {
  name: "Slmx",
  data() {
    return {
      srmxStatus,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      slmxList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open1: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ygId: null,
        backStatus: "1",
        name: null,
        qdkbId: null,
        withdrawalStatus: null,
      },
      qdkbData: {},
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        money: [{ required: true, message: "金额不能为空", trigger: "blur" }],
        reason: [{ required: true, message: "原因不能为空", trigger: "blur" }],
      },
      restate: true,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    seeqdkb(qdkbId) {
      getQdkb(qdkbId).then((response) => {
        this.qdkbData = response.data;
        this.open1 = true;
      });
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listSlmx(this.queryParams).then((response) => {
        this.slmxList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        backStatus: "2",
        money: undefined,
        reason: null,
        slmxId: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    listTab() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.slmxId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    /** 修改按钮操作 */
    handleUpdate(row, state) {
      this.reset();
      this.form.slmxId = row.slmxId;
      this.form.money = row.money || undefined;
      this.restate = state;
      console.log(this.form);
      this.open = true;
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          const data = this.form;
          const flag = this.restate;
          let backStatus = this.form.backStatus;
          let money = this.form.money;
          let tigs =
            backStatus == "2"
              ? "金额为：" + money + "元《请核对金额是否填写正确》"
              : "请详细明确原因";
          this.$modal
            .confirm(tigs)
            .then(function () {
              if (flag) {
                return updateSlmx(data);
              } else {
                return repeatUpdateSlmx(data);
              }
            })
            .then(() => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const slmxIds = row.slmxId || this.ids;
      this.$modal
        .confirm('是否确认删除编号为"' + slmxIds + '"的数据项？')
        .then(function () {
          return delSlmx(slmxIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/slmx/export",
        {
          ...this.queryParams,
        },
        `收入明细_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
